<template>
  <el-dialog title="备注" v-model="visible" width="420px" :close-on-click-modal="false" :show-close="false" :close-on-press-escape="false">
    <el-form class="remarkForm" ref="formRef" :model="remarkData.form" :status-icon="true" :show-message="false">
      <el-form-item prop="remark" required>
        <el-input class="remark_input" v-model="remarkData.form.remark" :placeholder="'请输入取消原因'" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <Button label="取消" @click="onCancelClick" />
      <Button type="primary" label="确定" @click="onSubmitClick" />
    </template>
  </el-dialog>
</template>

<script setup>
import { reactive, ref, computed, nextTick } from 'vue'
import Button from '@/components/button/button.vue'

const emit = defineEmits(['update:visible', 'change'])
const props = defineProps(['visible', 'orderId'])

const visible = computed({
  get: () => {
    return props.visible
  },
  set: (value) => emit('update:visible', value)
})

const formRef = ref(null)
const remarkData = reactive({
  form: {}
})

const hide = () => {
  visible.value = false

  formRef.value.clearValidate()
  formRef.value.resetFields()

  // nextTick(() => {
  //   formRef.value.clearValidate()
  // })
}

const onCancelClick = () => {
  hide()
}

const onSubmitClick = () => {
  formRef.value.validate((valid) => {
    if (valid) {
      emit('change', remarkData.form.remark)
      hide()
    }
  })
}
</script>
<style scoped lang="scss">
.remarkForm {
  padding: 0 15px;

  .remark_input {
    width: 390px;
    height: 70px;
  }
}
</style>
